package com.hualan.sfzy.controller.subscribeConsult;

import com.hualan.sfzy.entity.subscribeConsult.SubscribeConsult;
import com.hualan.sfzy.service.subscribeConsult.SubscribeConsultService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SubscribeConsultController {
    @Autowired
    private SubscribeConsultService subscribeConsultService;

    @PostMapping("/subscribeConsult")
    public Result add(@RequestBody SubscribeConsult subscribeConsult){
        int num = subscribeConsultService.add(subscribeConsult);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/subscribeConsult/{id}")
    public Result remove(@PathVariable Integer id){
        int num = subscribeConsultService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/subscribeConsult")
    public Result removeBatch(Integer[] ids){
        int num = subscribeConsultService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/subscribeConsult")
    public Result edit(@RequestBody SubscribeConsult subscribeConsult){
        int num = subscribeConsultService.edit(subscribeConsult);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/subscribeConsult/{id}")
    public Result findById(@PathVariable Integer id){
        SubscribeConsult subscribeConsult = subscribeConsultService.findById(id);
        return Result.success(subscribeConsult);
    }

    @GetMapping("/subscribeConsult/page")
    public Result findByPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",required = false,defaultValue = "1") Integer pageSize,
                                         SubscribeConsult subscribeConsult){
        Map<String, Object> map = subscribeConsultService.findByPage(pageNum, pageSize, subscribeConsult);
        return Result.success(map);
    }

    @GetMapping("/subscribeConsult")
    public Result find(){
        List<SubscribeConsult> list = subscribeConsultService.find();
        return Result.success(list);
    }
}
